package com.usdt.web.core.config;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
	
	@Autowired
	private OpenApiInterceptor openApiInterceptor;
	
	// 注册sa-token的拦截器 ，打开注解式鉴权功能 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	
        // 注册Sa-Token的路由拦截器  打开注解式鉴权功能 
        // 注册路由拦截器，自定义验证规则 ,排除登录接口(校验登录)
    	//我们注册了一个登录验证拦截器，并且排除了/user/doLogin接口用来开放登录（除了/user/doLogin以外的所有接口都需要登录才能访问）
        //registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
        	//.addPathPatterns("/**").excludePathPatterns(Arrays.asList("/swagger-ui.html", "/swagger-resources/**", "/v3/**", "/webjars","/webjars/**","/doc.html","/swagger**/**","/**"));
        
        registry.addInterceptor(openApiInterceptor)
        	.addPathPatterns("/**")
        	.excludePathPatterns(Arrays.asList("/swagger-ui.html", "/swagger-resources/**", "/v3/**", 
            		"/webjars","/webjars/**","/doc.html","/swagger**/**","/system/**","/oss/**"));
    }
	
}
